package com.awenhui.demo.service.impl;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yuxf
 * @version 1.0
 * @date 2021/1/25 15:42
 */
@Service
@CacheConfig(cacheNames = "user")
public class CacheServiceImpl {

    @Cacheable(value = "user",key = "#id")
    public Object getUserById(Integer id) {
        System.out.println("获取缓存中："+id+"的数据");
        Map<String, String> map = new HashMap<>();
        map.put("name", "yuxf");
        map.put("age", id+"");
        return map;
    }
}
